<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	
</body>
<script>
	

var array = [5,6,7,2,3,4,89,45,21,47];

function charu(array) {
	for(let i = 1;i<array.length;i++){
		let key = array[i],left = 0,right = i - 1;
		while(left <= right){
			let middle = parseInt((left + right)/2);
			if (key < array[middle]) {
				right = middle -1;
			}else{
				left = middle + 1;
			}
		}
		for(let j = i - 1;j>=left;j--){
			array[j+1] = array[j];
		}
		array[left] = key;
	}
	return array;
}

function bianli(array){
  for(let i = 0; i < array.length; i++){
    console.log(array[i]);
  }
}

bianli(charu(array));
 
</script>
</html>